package com.aizhixin.lab.project.template.service;

import com.aizhixin.lab.post.domain.SkillPointsDomain;
import com.aizhixin.lab.post.entity.SkillPoints;
import com.aizhixin.lab.project.template.entity.ProjectSkillPoints;
import com.aizhixin.lab.project.template.repository.ProjectSkillPointsRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@Transactional
public class ProjectSkillPointsService {
    @Autowired
    private ProjectSkillPointsRepository pointsRepository;

    public ProjectSkillPoints save(ProjectSkillPoints skillPoints){
        return pointsRepository.save(skillPoints);
    }
    public List<ProjectSkillPoints> save(List<ProjectSkillPoints> pointsList){
        return pointsRepository.save(pointsList);
    }
    public List<ProjectSkillPoints> findSkillPointsList(String id){
        return pointsRepository.findBySkillId(id);
    }
    public Integer delete(String skillId){
        return pointsRepository.deleteBySkillId(skillId);
    }
    public List<SkillPointsDomain> findSkillPoints(String skillId){
        List<ProjectSkillPoints> skillPointsList = pointsRepository.findBySkillId(skillId);
        List<SkillPointsDomain> domainList=new ArrayList<>();
        for (ProjectSkillPoints skillPoints:skillPointsList){
            SkillPointsDomain pointsDomain = new SkillPointsDomain();
            BeanUtils.copyProperties(skillPoints,pointsDomain);
            domainList.add(pointsDomain);
        }
        return domainList;
    }
    public List<ProjectSkillPoints> findList(List<String> idList){
        return pointsRepository.findAll(idList);
    }
}
